﻿using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using CuteRibs.WowArmory.Models;

namespace CuteRibs.WowArmory
{
	[ComVisible(true)]
	public class AppException : Exception
	{
		private AppException(string message)
			: base(message) { }

		private AppException(Exception innerException)
			: base(innerException.Message, innerException) { }

		public override string ToString()
		{
			var sb = new StringBuilder();
			sb.AppendLine();

			foreach (var p in this.Data.Keys.OfType<string>())
			{
				sb.AppendLine();
				sb.AppendFormat("{0}: {1}", p, this.Data[p]);
			}

			sb.AppendLine();
			return base.ToString() + sb.ToString();
		}

		public static AppException CreateException(string message, string region)
		{
			var ex = new AppException(message);
			ex.Data["Region"] = region;
			return ex;
		}

		public static AppException CreateRealmException(string message, string region, string realm)
		{
			var ex = new AppException(message);
			ex.Data["Region"] = region;
			ex.Data["Realm"] = realm;
			return ex;
		}

		public static AppException CreateCharacterException(string message, string region, string realm, string character)
		{
			var ex = new AppException(message);
			ex.Data["Region"] = region;
			ex.Data["Realm"] = realm;
			ex.Data["Character"] = character;
			return ex;
		}

		public static AppException CreateGuildException(string message, string region, string realm, string guild)
		{
			var ex = new AppException(message);
			ex.Data["Region"] = region;
			ex.Data["Realm"] = realm;
			ex.Data["Guild"] = guild;
			return ex;
		}

		public static AppException CreateException(Exception innerException, string region)
		{
			var ex = new AppException(innerException);
			ex.Data["Region"] = region;
			return ex;
		}

		public static AppException CreateRealmException(Exception innerException, string region, string realm)
		{
			var ex = new AppException(innerException);
			ex.Data["Region"] = region;
			ex.Data["Realm"] = realm;
			return ex;
		}

		public static AppException CreateCharacterException(Exception innerException, string region, string realm, string character)
		{
			var ex = new AppException(innerException);
			ex.Data["Region"] = region;
			ex.Data["Realm"] = realm;
			ex.Data["Character"] = character;
			return ex;
		}

		public static AppException CreateGuildException(Exception innerException, string region, string realm, string guild)
		{
			var ex = new AppException(innerException);
			ex.Data["Region"] = region;
			ex.Data["Realm"] = realm;
			ex.Data["Guild"] = guild;
			return ex;
		}
	}
}
